package com.zlp.controller;

import com.zlp.common.api.Result;
import com.zlp.dto.test.*;
import com.zlp.entity.SupplierCardDetail;
import com.zlp.factory.SupplierCouponFactory;
import com.zlp.service.SupplierCardDetailService;
import com.zlp.stategy.CouponSupplierStategy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Classname SupplierController
 * @Date 2022/9/21 12:57
 * @Created by ZouLiPing
 */
@RestController
@RequestMapping("/supplier")
@RequiredArgsConstructor
@Api(value = "supplier", tags = "供应商卡券接口")
public class SupplierController {

    private final SupplierCardDetailService supplierCardDetailService;



    /**
     *
     * ============ lh =======================
     * {
     *     "skuNoList":["T1888881"],
     *     "supplierCode":2000
     * }
     *
     *
     * @author ZouLiPing
     * @param supplierSkuReq
     * @date 2022/10/29 19:39
     * @return com.zlp.common.api.Result<java.util.List<com.zlp.dto.test.SupplierSkuDTO>>
     */
    @ApiOperation( "获取供应商sku信息列表")
    @PostMapping(value = "getSupplierSkuList")
    public Result<List<SupplierSkuDTO>> getSupplierSkuList(@Valid @RequestBody SupplierSkuReq supplierSkuReq){
        
        CouponSupplierStategy couponSupplierStategy = SupplierCouponFactory.invokeExecutor(supplierSkuReq.getSupplierCode());
        List<SupplierSkuDTO> response = couponSupplierStategy.getSupplierSkuList(supplierSkuReq);
        return Result.success(response);
    }

    @ApiOperation( "获取供应商基础信息列表")
    @PostMapping(value = "/api/supplier/getCouponBaseInfo")
    public Result<List<SupplierBaseDTO>> getCouponBaseInfo(@RequestBody SupplierCouponReq supplierCouponReq)  {
        supplierCouponReq.validate();
        CouponSupplierStategy couponSupplierStrategy = SupplierCouponFactory.invokeExecutor(supplierCouponReq.getSupplierCode());
        List<SupplierBaseDTO> response = couponSupplierStrategy.getCouponBaseInfo(supplierCouponReq);
        return Result.success(response);

    }


    /**
     *
     * {
     * 	"cusOrderNo": "VOLOV0G19075668065",
     * 	"cusSkuList": [
     *                {
     * 			"cusSkuNo": "LHSK0000002005",
     * 			"skuNum": 1
     *        },
     *        {
     * 			"cusSkuNo": "LHSK0000002006",
     * 			"skuNum": 1
     *        }
     * 	],
     * 	"supplierCode": 2000
     * }
     * 一个订单包含多张卡券
     * @author ZouLiPing
     * @date 2022/9/21 22:31
     * @return com.zlp.common.api.Result<java.util.List<com.zlp.dto.test.SupplierSkuDTO>>
     */
    @ApiOperation( "电子卡券订单提交")
    @PostMapping(value = "createCoupon")
    public Result<SupplierCardCipherDTO> createCoupon(@Valid @RequestBody SupplierCouponCreateReq supplierCouponCreateReq){

        CouponSupplierStategy couponSupplierStategy = SupplierCouponFactory.invokeExecutor(supplierCouponCreateReq.getSupplierCode());
        SupplierCardCipherDTO response = couponSupplierStategy.createCoupon( supplierCouponCreateReq);
        return Result.success(response);
    }

    /**
     * 查询第三方供应商卡券信息
     * @author ZouLiPing
     * @date 2022/9/21 22:31
     * @return com.zlp.common.api.Result<java.util.List<com.zlp.dto.test.SupplierSkuDTO>>
     */
    @ApiOperation( "查询第三方供应商卡券信息")
    @PostMapping(value = "getCouponOrderInfo")
    public Result<SupplierCardCipherDTO> getCouponOrderInfo(@Valid @RequestBody CouponOrderReq couponOrderReq){

        return Result.success(null);
    }

    @ApiOperation( "批量添加卡号和卡密")
    @PostMapping(value = "addSupplierCardDetails")
    public Result<SupplierCardCipherDTO> addSupplierCardDetails(@RequestBody List<SupplierCardDetail> records){


        supplierCardDetailService.addSupplierCardDetails(records);

        return Result.success(null);
    }

    @ApiOperation( "批量查询卡号和卡密")
    @PostMapping(value = "getSupplierCardDetails")
    public Result<List<SupplierCardDetail>> getSupplierCardDetails(@RequestBody List<Integer> supplierCardIds){

        List<SupplierCardDetail> supplierCardDetailList = supplierCardDetailService.getSupplierCardDetails(supplierCardIds);
        return Result.success(supplierCardDetailList);
    }


}
